package com.ms.seguridad.service;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Arrays;
import java.util.Collection;

/**
 * User: AW
 * Date: 24/02/13
 */
public class DpwcAuthenticationToken extends UsernamePasswordAuthenticationToken {
    private Object portal;
    private String ipAddress;

    //~ Constructors ===================================================================================================

    /**
     * This constructor can be safely used by any code that wishes to create a
     * <code>DpwcAuthenticationToken</code>, as the {@link
     * #isAuthenticated()} will return <code>false</code>.
     */
    public DpwcAuthenticationToken(Object principal, Object credentials) {
        super(principal, credentials);
        setAuthenticated(false);
    }

    public DpwcAuthenticationToken(Object principal, Object credentials, Object portal,String ipAddress) {
        this(principal, credentials);
        this.portal = portal;
        this.ipAddress = ipAddress;
    }

    /**
     * @deprecated use the list of authorities version
     */
    public DpwcAuthenticationToken(Object principal, Object credentials, GrantedAuthority[] authorities) {
        this(principal, credentials, Arrays.asList(authorities));
    }

    /**
     * This constructor should only be used by <code>AuthenticationManager</code> or <code>AuthenticationProvider</code>
     * implementations that are satisfied with producing a trusted (i.e. {@link #isAuthenticated()} = <code>true</code>)
     * authentication token.
     *
     * @param principal
     * @param credentials
     * @param authorities
     */
    public DpwcAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(principal, credentials, authorities);
    }

    public DpwcAuthenticationToken(Object principal, Object credentials, Object portal, Collection<? extends GrantedAuthority> authorities) {
        this(principal, credentials, authorities);
        this.portal = portal;
    }


    //~ Methods ========================================================================================================

    public Object getPortal() {
        return portal;
    }

    public String getIpAddress() {
        return ipAddress;
    }
}
